const path = require('path');
const  { VueLoaderPlugin }= require('vue-loader');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');

module.exports = {
  mode:'none',
  entry: path.join(__dirname, 'src/main.js'),
  output: {
    filename: 'bundle.js',
    path: path.join(__dirname, 'dist'),
  },
  // resolve: {
  //   extensions: ['.js', '.json', '.css', '.vue'],
  // },
  devServer: {
    contentBase: path.join(__dirname, 'public'), //指定额外静态资源路径，他可以是字符串，也可以是数组；
    port: 5090,
    hot: true,
    open: true
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      } ,
      {
        test: /\.js$/,
        exclude:/node_modules/,
        // include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
        loader: ['babel-loader']
      },
      { 
        test: /\.css$/,
        use: [
          'vue-style-loader', 
          'css-loader'
        ], 
      },

      {
        test: /\.less$/,
        loader:  [
          'style-loader',
          'css-loader',
          'less-loader'
        ],
      }, 
      {
        enforce: 'pre',           // 在webpack编译之前进行检测
        test: /.(js|vue)$/,
        loader: 'eslint-loader',
        exclude: [                // 除去node_modules
          path.resolve(__dirname, '../node_modules')
        ] 
      }, 
      {
        test: /\.(png|jpe?g|gif|svg|ico)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10*1024, //单位是字节 10KB，超过10KB使用file-loader
          esModule: false //url-loader默认导出esm,而@vue/component-compiler-utils按照commonJs解析

        }
      }
    ]
  },
  plugins: [
    new VueLoaderPlugin(),
    new HtmlWebpackPlugin({
      title: 'wh-Vue-Webpack',
      template: './public/index.html',
      filename: 'index.html',
    }),
    new webpack.DefinePlugin({
      BASE_URL: JSON.stringify('/'),
    }),
  ],

};
